package demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 跨域配置类
 *
 * @author 肖溥博文
 * @version 1.2
 */
@Configuration
public class CrosConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
            .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
            .allowedOrigins("http://localhost:8081", "http://47.96.106.251:8081", "http://47.96.106.251:8081/*", "http://localhost:8081/*")
            .allowCredentials(true)
            .maxAge(3600)
            .allowedHeaders("*");
    }
}
